﻿// =================================================================== 
// 项目说明
//====================================================================
// lsc @Copy Right 2019
// 文件： TrailCommentRepository.cs
// 项目名称：斑马车务
// 创建时间：2019-07-31
// 负责人：lsc
// ===================================================================
using System;
using System.Text;
using System.Collections.Generic;
using YouWei.Infrastructure.Entity;
using Dapper.Extensions;
using YouWei.Infrastructure.Models;

namespace YouWei.Infrastructure.Repository
{
    /// <summary>
    ///评论-留言 仓储层
    /// </summary>	
    public class TrailCommentRepository : BaseRepository<TrailComment>
    {

        #region 构造

        public TrailCommentRepository() : base() { }

        public TrailCommentRepository(string connectionString) : base(connectionString) { }

        public TrailCommentRepository(DatabaseContext dbContext) : base(dbContext) { }

        #endregion

        /// <summary>
        /// 根据群空间内容id获取评论
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="commentId"></param>
        /// <returns></returns>
        public Page<TrailCommentDto> Pages(int pageIndex, int pageSize, int commentId, int isShow)
        {
            string sql = "SELECT  t1.*, t2.UserName AS WxNickName, t2.UserHead AS WxHeadImgUrl FROM TrailComment t1 WITH ( NOLOCK ) LEFT JOIN UserInfo t2 WITH ( NOLOCK ) ON t1.UserID = t2.UserID";
            sql += "   where t1.TrailIdentity = " + commentId;
            if (isShow == 1)
            {
                sql += "   and t1.IsShow = 1";
            }
            sql += "   ORDER BY t1.TrailCommentID desc";
            return dbContext.Connection.Page<TrailCommentDto>(pageIndex, pageSize, sql);
        }
        /// <summary>
        /// 获取评论列表,默认不筛选审核
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public Page<TrailCommentDto> Pages(int pageIndex, int pageSize, int isShow=-1)
        {
            string sql = "SELECT  t1.*, t2.UserName AS WxNickName, t2.UserHead AS WxHeadImgUrl FROM TrailComment t1 WITH ( NOLOCK ) LEFT JOIN UserInfo t2 WITH ( NOLOCK ) ON t1.UserID = t2.UserID";
            if (isShow != -1)
            {
                sql += "   where t1.IsShow = "+isShow;
            }
            sql += "   ORDER BY t1.TrailCommentID desc";
            return dbContext.Connection.Page<TrailCommentDto>(pageIndex, pageSize, sql);
        }
    }
}